package com.zuihai.app.mvp.ui.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ImageView;

/**
 * Created by Panda_Program on 2017/11/12 0012.
 */

public class VidewImageView extends ImageView {
    //是否释放了
    private boolean isReleased;
    //计数器，防止多次点击导致最后一次形成longpress的时间变短
    private int mCounter;
    //长按的runnable
    private Runnable mLongPressRunnable;
    //定义相应时间 以此为依据判断是长按还是短按 默认为300毫秒
    private int minTime = 300;

    public int getMinTime() {
        return minTime;
    }

    public void setMinTime(int minTime) {
        this.minTime = minTime;
    }

    public OnTakePhotoClickListener getShortClickListener() {
        return shortClickListener;
    }

    public OnLongTakePhotoClickListener getLongClickListener() {
        return longClickListener;
    }

    private OnTakePhotoClickListener shortClickListener;

    private OnLongTakePhotoClickListener longClickListener;


    public void setShortClickListener(OnTakePhotoClickListener shortClickListener) {
        this.shortClickListener = shortClickListener;
    }

    public void setLongClickListener(OnLongTakePhotoClickListener longClickListener) {
        this.longClickListener = longClickListener;
    }

    public VidewImageView(Context context) {
        this(context, null, 0);
    }

    public VidewImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public VidewImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public VidewImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        this(context, attrs, defStyleAttr);
    }

    public boolean dispatchTouchEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                //mCounter++;
                // isReleased = false;
                longClickListener.onStartVideo();
                break;
            case MotionEvent.ACTION_MOVE:
                break;

            case MotionEvent.ACTION_UP:
                longClickListener.onEndVideo();
                break;
        }
        return true;
    }

    /**
     * 为长按拍照设置一个监听事件
     */
    public interface OnLongTakePhotoClickListener {

        void onStartVideo();

        void onEndVideo();
    }

    /**
     * 为短按拍照设置一个监听事件
     */
    public interface OnTakePhotoClickListener {
        void onClick();
    }
}